'''
Created on Jul 24, 2009

@author: Roni
'''
import graph
import tests.mdpAbstractTest
import cliques.cliqueStarSearch
import cliques.mdp.mdpBasedSearch
import cliques.utils
import cliques.mdp.offlineMdpSolver
import cliques.cliqueFinder
class unittest_ldfs(tests.mdpAbstractTest.mdpAbstractTest):
    '''
    classdocs
    '''
    def mtestCliqueStarBetter(self):       
        lookahead_depth = 5
        alg_offline = cliques.mdp.mdpBasedSearch.mdpBasedSearch(cliques.mdp.offlineMdpSolver.offlineMdpSolver,"Offline-5",5)
        alg_cs = cliques.cliqueStarSearch.cliqueStarSearch()
        algorithms = [alg_offline,alg_cs]
        self.clique_search_run_comparator(6, 4, 6, algorithms, [self.assert_current_node])

    def clique_search_run_comparator(self,nodes,min_k,max_k,algorithms,comp_funcs):
        clique_finder = cliques.cliqueFinder.cliqueFinder()
        for edges in xrange(min(nodes+5,nodes*(nodes-1)/2),min(nodes+10,nodes*(nodes-1)/2)):#xrange(nodes+1,nodes*(nodes-1)/2,1):
            print "--- Generating graph[%d,%d] --- " % (nodes,edges)
            test_graph = graph.graph()
            test_graph.generate(nodes,edges)
            clique_finder.setup(test_graph)
            while clique_finder.has_clique(min_k, test_graph.nodes())==False:
                test_graph = graph.graph()
                test_graph.generate(nodes,edges)
                clique_finder.setup(test_graph)                
            
            self.compare(test_graph,min_k,max_k,algorithms,comp_funcs)
       
    def testOfflineBugGraph(self):
        FILE_NAME = "Offline-BUG-GRAPH[4,2].graph"
        bug_graph = cliques.utils.import_graph(FILE_NAME)
        nodes = 5
        lookahead_depth = nodes-1
        k=4
        start_node= u'2'
        alg_offline = cliques.mdp.mdpBasedSearch.mdpBasedSearch(cliques.mdp.offlineMdpSolver.offlineMdpSolver,"Offline-5",5)
        alg_cs = cliques.cliqueStarSearch.cliqueStarSearch()
        self.simulate_run(bug_graph, [alg_offline,alg_cs], [self.assert_halt], k, start_node)
        